package com.buli.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonInclude(JsonInclude.Include.NON_NULL) // 确保空字段不被序列化
public class Result<T> {
    private int code;
    private String message;

    @JsonProperty("data") // 明确指定字段名称
    private T data;

    // 添加构造方法，用于初始化状态值
    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    // 修改success方法，确保code字段被正确初始化
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>(200, "成功");
        result.data = data;
        return result;
    }

    // 修改fail方法，确保code字段被正确初始化
    public static <T> Result<T> fail(String message) {
        return new Result<>(500, message);
    }

    // Getter and Setter...
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}